import requests
import time

def timeit(func):
    def timed(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"Function {func.__name__} took {end_time - start_time} seconds")
        return result
    return timed

class CustomOpenAIClient:
    def __init__(self, api_key, base_url):
        self.api_key = api_key
        self.base_url = base_url
        self.headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }

    def chat_completions_create(self, model, messages, temperature=None, stream=False):
        url = f"{self.base_url}/v1/chat/completions"
        payload = {
            "model": model,
            "messages": messages,
            "stream": stream
        }
        response = requests.post(url, json=payload, headers=self.headers)
        response.raise_for_status()
        return response.json()

@timeit
def askKiMiByWeb(content, model="concise"):
    messages = [{'role': 'user', 'content': content}]
    client = CustomOpenAIClient(
        api_key="sk-ntikUIbQDL6y9pAsjLlseHZ32Oo7EZ7r2hmiMRWMFz0i6c8i",
        base_url="http://192.168.8.100:8000")
    response = client.chat_completions_create(model=model, messages=messages, stream=False)
    return response

# 测试函数
print(askKiMiByWeb("秘塔AI"))
